<?php
namespace App\Mappers\Trade;

use App\Mappers\DataMapper;
use App\Models\Trade\Demand\DemandModel;

class DemandMapper extends DataMapper
{

    public function make()
    {
        // 品种ID
        $this->offsetSet('kind_id', $this->kind_id);
        // 规格
        if ($this->size_unit_id == DemandModel::SIZE_UNIT_NONE) {
            $this->offsetSet('size_min', null);
            $this->offsetSet('size_max', null);
        } else {
            $this->offsetSet('size_min', $this->isValid('size_min') ? $this->size_min : null);
            $this->offsetSet('size_max', $this->isValid('size_max') ? $this->size_max : null);
        }
        // 规格单位
        $this->offsetSet('size_unit_id', $this->size_unit_id);
        // 价格
        $this->offsetSet('price_type', $this->price_type);
        if ($this->price_type == DemandModel::PRICE_TYPE_CUSTOM) {
            $this->offsetSet('price', $this->price);
        } else {
            $this->offsetSet('price', null);
        }
        // 价格单位
        $this->offsetSet('price_unit_id', $this->price_unit_id);
        // 库存
        $this->offsetSet('stock', $this->stock);
        // 地址
        $this->offsetSet('province', $this->province);
        $this->offsetSet('city', $this->city);
        $this->offsetSet('area', $this->area);
        $this->offsetSet('town', $this->isValid('town') ? $this->town : null);
        $this->offsetSet('address', $this->isValid('address') ? $this->address : null);
        // 有效期至
        $this->offsetSet('valided', $this->valided);
        // 描述
        $this->offsetSet('desc', $this->isValid('desc') ? $this->desc : null);
        if ($this->isValid('desc_tag') && count($this->desc_tag)) {
            $this->offsetSet('desc_tag', json_encode($this->desc_tag));
        } else {
            $this->offsetSet('desc_tag', null);
        }
        // 物流
        $this->offsetSet('logistics', $this->logistics);
        // 联系人
        $this->offsetSet('contact_name', $this->contact_name);
        $this->offsetSet('contact_mobile', $this->contact_mobile);
        
        return $this;
    }
}